package com.github.skystardust.lotteryex.lottery.item.imp.award;

import com.github.skystardust.lotteryex.LotteryEX;
import com.github.skystardust.lotteryex.lottery.item.AwardItem;
import com.github.skystardust.lotteryex.utils.OptionalUtils;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.bukkit.entity.Player;

import java.util.Map;
import java.util.UUID;

@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class AwardItemPermission extends AwardItem<String> {
    public AwardItemPermission(String awardItem) {
        super(awardItem);
    }

    public AwardItemPermission(UUID uuid, String awardItem, int chance) {
        super(uuid, awardItem);
    }

    public AwardItemPermission(Map<String, Object> stringObjectMap) {
        super(stringObjectMap);
        setAwardItem(((String) stringObjectMap.get("awardItem")));
    }

    @Override
    public void giveAward(Player player) {
        new OptionalUtils<>(() -> LotteryEX.getLotteryEX().getVaultHook().getPermission()).getOptional().ifPresent(permission -> {
            permission.playerAdd(player, getAwardItem());
        });
    }
}
